package cn.wolfcode.wolf2w.business.service.impl;

import cn.wolfcode.wolf2w.business.service.ISmsService;

import cn.wolfcode.wolf2w.business.util.SmsUtil;
import cn.wolfcode.wolf2w.common.redis.service.RedisService;
import cn.wolfcode.wolf2w.common.redis.util.RedisKeys;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Random;
import java.util.UUID;
import java.util.concurrent.TimeUnit;

@Service
public class SmsServiceImpl implements ISmsService {

    @Autowired
    private RedisService redisService;

    @Override
    public void senVerifyCode(String phone) {

//        String code = UUID.randomUUID().toString().replace("-", "").substring(6);

        Integer code = new Random().nextInt(90000) + 10000;
        SmsUtil.sendSmsAli(phone,code.toString());
        //存储验证码
        String key = RedisKeys.VERIFY_CODE.join(phone);
        redisService.setNXCacheObject(key,code.toString(),RedisKeys.VERIFY_CODE.getTime(), TimeUnit.SECONDS);
        System.err.println("验证码：" + code);
    }
}
